/*
2010/8/22 18:04:29
*/


namespace LanSunSystem
{
    using System;
    using System.ServiceModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;

    public class ProcessFlowHead : QueryCommand
    {
        public ProcessFlowHead() : base() { }
        public ProcessFlowHead(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }
        public SqlCommand BuildCommand()
        {

            switch (RequestJob.Substring(6,4))
            {
                case "0000": 
                /*
                     case "ProcessFlowHead":
                        ProcessFlowHead m_ProcessFlowHead = new ProcessFlowHead(cmdSQL, dtRequest, RequestJob);
                        cmdSQL = m_ProcessFlowHead.BuildCommand();
                        break;
                */
                    break;
                case "1000": 
                    break;
                 case "2001":
                 case "4000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break; 
                    case "1001":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                break;
                    case "1002":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                break;
                    case "1003":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                break;
                    case "1004":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                break;
                    case "1005":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                break;
                    case "1006":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                    cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));                     
                break;
                case "1007":    //IX_GoodsTypeKeyDef
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                break;
                case "1008":    //IX_ProcessFlowHead
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                break;
                case "1009":    //IX_ProcessFlowHead_GoodsTypeKeyDefKey
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                break;
                case "1010":    //IX_ProcessFlowHead_Key
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                break;
                case "1011":    //IX_ProcessFlowHead_MasterKey
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                break;
                case "1012":    //IX_ProcessFlowHead_Parent
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                break;
                case "1013":    //PK_ProcessFlowHead
                cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));                     
                cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));                     
                break;
                
               case "2000": 
               case "3000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    cmdSQL = BuildInstanceKey(cmdSQL, dwRequest);
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyID", dwRequest["GoodsKeyID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Source", dwRequest["Source"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyLevel", dwRequest["GoodsKeyLevel"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ProcessFlowHeadID", dwRequest["ProcessFlowHeadID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ProcessFlowHeadKey", dwRequest["ProcessFlowHeadKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastPositionID", dwRequest["LastPositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ExtenedProperty", dwRequest["ExtenedProperty"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    break;
            }
            return cmdSQL;

        }
        public override SqlCommand BuildInstanceKey(SqlCommand cmdSQL, DataRow dwTemp)
        {
            
                string InstanceKey = dwTemp["InstanceKey"].ToString().Trim();
                    string SysID=dwTemp["SysID"].ToString().Trim();
                    string KeyDefType=dwTemp["KeyDefType"].ToString().Trim();
                    string GoodsTypeKey=dwTemp["GoodsTypeKey"].ToString().Trim();
                    string GoodsTypeKeyDefKey=dwTemp["GoodsTypeKeyDefKey"].ToString().Trim();
                    string GoodsKey=dwTemp["GoodsKey"].ToString().Trim();
                    string PositionID=dwTemp["PositionID"].ToString().Trim();
           
            {
                if (SysID!=""&&KeyDefType!=""&&GoodsTypeKey!=""&&GoodsTypeKeyDefKey!=""&&GoodsKey!=""&&PositionID!="")
                {
                    InstanceKey =SysID+"."+KeyDefType+"."+GoodsTypeKey+"."+GoodsTypeKeyDefKey+"."+GoodsKey+"."+PositionID;
                    dwTemp["InstanceKey"] = InstanceKey;
                    dwTemp.AcceptChanges();
                }
            }
            cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
            return base.BuildInstanceKey(cmdSQL, dwTemp);
        }
}
 public class ProcessFlowHeadQueryCond : QueryCommand
    {
        public ProcessFlowHeadQueryCond() : base() { }
        public ProcessFlowHeadQueryCond(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
         : base(cmdSQL, dtRequest,RequestJob) {  }

        public SqlCommand BuildCommand()
        {
            switch (RequestJob.Substring(6,4))
            {
                case "0000": break;
                case "1000": break;
                case "1001": break;
                case "1002": break;
                case "2000": 
                case "3000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyID", dwRequest["GoodsKeyID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@Source", dwRequest["Source"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@GoodsKeyLevel", dwRequest["GoodsKeyLevel"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@ProcessFlowHeadID", dwRequest["ProcessFlowHeadID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@ProcessFlowHeadKey", dwRequest["ProcessFlowHeadKey"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastPositionID", dwRequest["LastPositionID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@ExtenedProperty", dwRequest["ExtenedProperty"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@FrstUser", dwRequest["FrstUser"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@FrstDate", dwRequest["FrstDate"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastUser", dwRequest["LastUser"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastDate", dwRequest["LastDate"].ToString()));
                
                    break;
                case "4000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString())); 
                    break;
            }
             return cmdSQL;

        }      

    }
 }

